<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/11/17
 * Time: 21:38
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\admin\controller;

use app\common\business\Admin as BusObj;
use app\common\lib\Show;
use app\common\lib\Status;
use think\App;
use think\facade\Session;

class Pwd extends Base
{
    protected BusObj $busObj;
    protected $indexWhere = [];

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->busObj = new BusObj();

    }

    public function index()
    {
        return parent::index(); // TODO: Change the autogenerated stub
    }

    public function saveBtn()
    {
        $old_password = $this->request->param('old_password', '', 'trim');
        $new_password = $this->request->param('new_password', '', 'trim');
        $again_password = $this->request->param('again_password', '', "trim");
        $data = [
            "old_password" => $old_password,
            "new_password" => $new_password,
            "again_password" => $again_password,
            "admin"=>$this->request->admin
        ];
        try {
            $result = $this->busObj->saveBtn($data);
        }catch (\Exception $e){
            return Show::json_show(Status::status_error,$e->getMessage());
        }
        if($result){
            Session::set(config('admin.admin_session_key'),null);
            return Show::json_show(Status::status_normal,"修改成功");
        }else{
            return Show::json_show(Status::status_error,"修改失败");
        }
    }
}